package com.yj_app.qualitytest.adapter;

import android.text.TextUtils;
import android.view.View;

import androidx.annotation.NonNull;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.chad.library.adapter.base.entity.MultiItemEntity;
import com.yj_app.qualitytest.R;
import com.yj_app.qualitytest.info.SubScoreInfo;
import com.yj_app.qualitytest.info.Title2LInfo;
import com.yj_app.qualitytest.info.TitleInfo;

import java.text.DecimalFormat;
import java.util.List;

public class SeeDetailAdapter extends BaseMultiItemQuickAdapter<MultiItemEntity, BaseViewHolder> {
    public static final int TYPE_LEVEL_0 = 0;
    public static final int TYPE_LEVEL_1 = 1;
    public static final int TYPE_LEVEL_2 = 2;
    /**
     * Same as QuickAdapter#QuickAdapter(Context,int) but with
     * some initialization data.
     *
     * @param data A new list is created out of this one to avoid mutable list
     */
    public SeeDetailAdapter(List<MultiItemEntity> data) {
        super(data);
        addItemType(TYPE_LEVEL_0, R.layout.item_maingrid_lv0);
        addItemType(TYPE_LEVEL_1, R.layout.item_maingrid_lv1);
        addItemType(TYPE_LEVEL_2, R.layout.item_see_detail_content);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, MultiItemEntity item) {
        switch (helper.getItemViewType()) {
            case TYPE_LEVEL_0:
                TitleInfo queInfo = (TitleInfo) item;
                helper.setText(R.id.leve0_title,queInfo.getTitle());
                helper.itemView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        int pos = helper.getAdapterPosition();
                        if (queInfo.isExpanded()) {
                            collapse(pos);
                        } else {
                            expand(pos);
                        }
                    }
                });

                break;
            case TYPE_LEVEL_1:
                DecimalFormat decimalFormat = new DecimalFormat("###0.#");
                Title2LInfo title2LInfo = (Title2LInfo) item;

                helper.setText(R.id.score_content,title2LInfo.getTitle());
                helper.setText(R.id.score_value,(title2LInfo.getKscore()!=0)?decimalFormat.format(100-title2LInfo.getKscore()):"");
                helper.itemView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        int pos = helper.getAdapterPosition();
                        if (title2LInfo.isExpanded()) {
                            collapse(pos);
                        } else {
                            expand(pos);
                        }
                    }
                });
                break;
            case TYPE_LEVEL_2:
                SubScoreInfo repositoryInfo= (SubScoreInfo) item;

                helper.setText(R.id.tostring_content,repositoryInfo.getBzLxName()+"\t"+repositoryInfo.getCheckXmName()+"\t"+repositoryInfo.getWorkspacename()
                +"\t"+repositoryInfo.getSclinename()+"\t"+repositoryInfo.getZrname()+"\t"+repositoryInfo.getTeamname()+"\t"+
                        repositoryInfo.getContentId()+"\t"+repositoryInfo.getMachineno()+"\t"+repositoryInfo.getBzfs());
                helper.setText(R.id.qscore_content,(repositoryInfo.getScore()==0)?repositoryInfo.getCommon():String.valueOf(repositoryInfo.getScore()));

                break;
        }


    }
}
